<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="本文将详细分析&lt; dubbo:service executes&#x3D;””&#x2F;&gt;与&lt; dubbo:reference actives &#x3D; “”&#x2F;&gt;的实现机制，深入探讨Dubbo自身的保护机制。 1、源码分析ExecuteLimitFilter@Activate(group &#x3D; Constants.PROVIDER, value &#x3D; Constants.EXECUTES_KEY )">
<meta property="og:type" content="article">
<meta property="og:title" content="源码分析Dubbo服务提供者、服务消费者并发度控制机制">
<meta property="og:url" content="https://www.codingw.net/posts/1ea63fb8.html">
<meta property="og:site_name" content="中间件兴趣圈">
<meta property="og:description" content="本文将详细分析&lt; dubbo:service executes&#x3D;””&#x2F;&gt;与&lt; dubbo:reference actives &#x3D; “”&#x2F;&gt;的实现机制，深入探讨Dubbo自身的保护机制。 1、源码分析ExecuteLimitFilter@Activate(group &#x3D; Constants.PROVIDER, value &#x3D; Constants.EXECUTES_KEY )">
<meta property="og:locale">
<meta property="article:published_time" content="2020-11-29T11:25:01.000Z">
<meta property="article:modified_time" content="2021-04-26T12:09:29.433Z">
<meta property="article:author" content="中间件兴趣圈">
<meta property="article:tag" content="中间件">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://www.codingw.net/posts/1ea63fb8.html"/>





  <title>源码分析Dubbo服务提供者、服务消费者并发度控制机制 | 中间件兴趣圈</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">中间件兴趣圈</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">微信搜『中间件兴趣圈』，回复『Java』获取200本优质电子书</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://www.codingw.net/posts/1ea63fb8.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="中间件兴趣圈">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">源码分析Dubbo服务提供者、服务消费者并发度控制机制</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-11-29T19:25:01+08:00">
                2020-11-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/dubbo/" itemprop="url" rel="index">
                    <span itemprop="name">dubbo</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/posts/1ea63fb8.html" class="leancloud_visitors" data-flag-title="源码分析Dubbo服务提供者、服务消费者并发度控制机制">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <div id="vip-container"><p>本文将详细分析&lt; dubbo:service executes=””/&gt;与&lt; dubbo:reference actives = “”/&gt;的实现机制，深入探讨Dubbo自身的保护机制。</p>
<h2 id="1、源码分析ExecuteLimitFilter"><a href="#1、源码分析ExecuteLimitFilter" class="headerlink" title="1、源码分析ExecuteLimitFilter"></a>1、源码分析ExecuteLimitFilter</h2><p>@Activate(group = Constants.PROVIDER, value = Constants.EXECUTES_KEY )</p>
<ul>
<li>过滤器作用<br>服务调用方并发度控制。</li>
<li>使用场景<br>对Dubbo服务提供者实现的一种保护机制，控制每个服务的最大并发度。</li>
<li>阻断条件<br>当服务调用超过允许的并发度后，直接抛出RpcException异常。<br>接下来源码分析ExecuteLimitFilter的实现细节。</li>
</ul>
<span id="more"></span>

<p>ExecuteLimitFilter#invoke</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">public Result invoke(Invoker&lt;?&gt; invoker, Invocation invocation) throws RpcException &#123;</span><br><span class="line">        URL url &#x3D; invoker.getUrl();</span><br><span class="line">        String methodName &#x3D; invocation.getMethodName();</span><br><span class="line">        Semaphore executesLimit &#x3D; null;</span><br><span class="line">        boolean acquireResult &#x3D; false;</span><br><span class="line">        int max &#x3D; url.getMethodParameter(methodName, Constants.EXECUTES_KEY, 0);      &#x2F;&#x2F; @1</span><br><span class="line">        if (max &gt; 0) &#123;</span><br><span class="line">            RpcStatus count &#x3D; RpcStatus.getStatus(url, invocation.getMethodName());             &#x2F;&#x2F; @2</span><br><span class="line">            executesLimit &#x3D; count.getSemaphore(max);                                                              &#x2F;&#x2F; @3</span><br><span class="line">            if(executesLimit !&#x3D; null &amp;&amp; !(acquireResult &#x3D; executesLimit.tryAcquire())) &#123;              &#x2F;&#x2F; @4</span><br><span class="line">                throw new RpcException(&quot;Failed to invoke method &quot; + invocation.getMethodName() + &quot; in provider &quot; + url + &quot;, cause: The service using threads </span><br><span class="line">                      greater than &lt;dubbo:service executes&#x3D;\&quot;&quot; + max + &quot;\&quot; &#x2F;&gt; limited.&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        boolean isSuccess &#x3D; true;</span><br><span class="line">        try &#123;</span><br><span class="line">            Result result &#x3D; invoker.invoke(invocation);                 &#x2F;&#x2F; @5</span><br><span class="line">            return result;</span><br><span class="line">        &#125; catch (Throwable t) &#123;</span><br><span class="line">            isSuccess &#x3D; false;</span><br><span class="line">            if (t instanceof RuntimeException) &#123;</span><br><span class="line">                throw (RuntimeException) t;</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                throw new RpcException(&quot;unexpected exception when ExecuteLimitFilter&quot;, t);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; finally &#123;</span><br><span class="line">            if(acquireResult) &#123;                                   &#x2F;&#x2F; @6</span><br><span class="line">                executesLimit.release();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>代码@1：从服务提供者列表中获取参数executes的值，如果该值小于等于0，表示不启用并发度控制，直接沿着调用链进行调用。</p>
<p>代码@2：根据服务提供者url和服务调用方法名，获取RpcStatus。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">public static RpcStatus getStatus(URL url, String methodName) &#123;</span><br><span class="line">        String uri &#x3D; url.toIdentityString();      </span><br><span class="line">        ConcurrentMap&lt;String, RpcStatus&gt; map &#x3D; METHOD_STATISTICS.get(uri);         </span><br><span class="line">        if (map &#x3D;&#x3D; null) &#123;</span><br><span class="line">            METHOD_STATISTICS.putIfAbsent(uri, new ConcurrentHashMap&lt;String, RpcStatus&gt;());    </span><br><span class="line">            map &#x3D; METHOD_STATISTICS.get(uri);</span><br><span class="line">        &#125;</span><br><span class="line">        RpcStatus status &#x3D; map.get(methodName);          &#x2F;</span><br><span class="line">        if (status &#x3D;&#x3D; null) &#123;</span><br><span class="line">            map.putIfAbsent(methodName, new RpcStatus());</span><br><span class="line">            status &#x3D; map.get(methodName);</span><br><span class="line">        &#125;</span><br><span class="line">        return status;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>这里是并发容器ConcurrentHashMap的经典使用，从 这里可以看出ConcurrentMap&lt; String, ConcurrentMap&lt; String, RpcStatus&gt;&gt; METHOD_STATISTICS的存储结构为 {  服务提供者URL唯一字符串：{方法名：RpcStatus} }。</p>
<p>代码@3：根据服务提供者配置的最大并发度，创建该服务该方法对应的信号量对象。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">public Semaphore getSemaphore(int maxThreadNum) &#123;</span><br><span class="line">        if(maxThreadNum &lt;&#x3D; 0) &#123;</span><br><span class="line">            return null;</span><br><span class="line">        &#125;</span><br><span class="line">        if (executesLimit &#x3D;&#x3D; null || executesPermits !&#x3D; maxThreadNum) &#123;</span><br><span class="line">            synchronized (this) &#123;</span><br><span class="line">                if (executesLimit &#x3D;&#x3D; null || executesPermits !&#x3D; maxThreadNum) &#123;</span><br><span class="line">                    executesLimit &#x3D; new Semaphore(maxThreadNum);</span><br><span class="line">                    executesPermits &#x3D; maxThreadNum;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        return executesLimit;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>使用了双重检测来创建executesLimit 信号量。</p>
<p>代码@4：如果获取不到锁，并不会阻塞等待，而是直接抛出RpcException,服务端的策略是快速抛出异常，供服务调用方（消费者）根据集群策略进行执行，例如重试其他服务提供者。</p>
<p>代码@5：执行真实的服务调用。</p>
<p>代码@6：如果成功申请到信号量，在服务调用结束后，释放信号量。<br>总结：&lt; dubbo:service executes=””/&gt;的含义是，针对每个服务每个方法的最大并发度。如果超过该值，则直接抛出RpcException。</p>
<h2 id="2、源码分析ActiveLimitFilter"><a href="#2、源码分析ActiveLimitFilter" class="headerlink" title="2、源码分析ActiveLimitFilter"></a>2、源码分析ActiveLimitFilter</h2><p>@Activate(group = Constants.CONSUMER, value = Constants.ACTIVES_KEY )</p>
<ul>
<li>过滤器作用<br>消费端调用服务的并发控制。</li>
<li>使用场景<br>控制同一个消费端对服务端某一服务的并发调用度，通常该值应该小于&lt; dubbo:service executes=””/&gt;</li>
<li>阻断条件<br>非阻断，但如果超过允许的并发度会阻塞，超过超时时间后将不再调用服务，而是直接抛出超时。</li>
</ul>
<p>源码分析ActiveLimitFilter的实现原理：<br>ActiveLimitFilter#invoke</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">public Result invoke(Invoker&lt;?&gt; invoker, Invocation invocation) throws RpcException &#123;</span><br><span class="line">        URL url &#x3D; invoker.getUrl();</span><br><span class="line">        String methodName &#x3D; invocation.getMethodName();</span><br><span class="line">        int max &#x3D; invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0);    &#x2F;&#x2F; @1</span><br><span class="line">        RpcStatus count &#x3D; RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName());           &#x2F;&#x2F; @2</span><br><span class="line">        if (max &gt; 0) &#123;                                          </span><br><span class="line">            long timeout &#x3D; invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0);   &#x2F;&#x2F; @3</span><br><span class="line">            long start &#x3D; System.currentTimeMillis();</span><br><span class="line">            long remain &#x3D; timeout;</span><br><span class="line">            int active &#x3D; count.getActive();                                                                                                                                          &#x2F;&#x2F; @4</span><br><span class="line">            if (active &gt;&#x3D; max) &#123;                                                                                                                                                          &#x2F;&#x2F; @5</span><br><span class="line">                synchronized (count) &#123;                                                                                                                                                                      </span><br><span class="line">                    while ((active &#x3D; count.getActive()) &gt;&#x3D; max) &#123;                                                                                                     </span><br><span class="line">                        try &#123;</span><br><span class="line">                            count.wait(remain);                                                                                                                                      </span><br><span class="line">                        &#125; catch (InterruptedException e) &#123;</span><br><span class="line">                        &#125;</span><br><span class="line">                        long elapsed &#x3D; System.currentTimeMillis() - start;                               </span><br><span class="line">                        remain &#x3D; timeout - elapsed;</span><br><span class="line">                        if (remain &lt;&#x3D; 0) &#123;                                                                                                                                             &#x2F;&#x2F; @6</span><br><span class="line">                            throw new RpcException(&quot;Waiting concurrent invoke timeout in client-side for service:  &quot;</span><br><span class="line">                                    + invoker.getInterface().getName() + &quot;, method: &quot;</span><br><span class="line">                                    + invocation.getMethodName() + &quot;, elapsed: &quot; + elapsed</span><br><span class="line">                                    + &quot;, timeout: &quot; + timeout + &quot;. concurrent invokes: &quot; + active</span><br><span class="line">                                    + &quot;. max concurrent invoke limit: &quot; + max);</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        try &#123;</span><br><span class="line">            long begin &#x3D; System.currentTimeMillis();</span><br><span class="line">            RpcStatus.beginCount(url, methodName);        &#x2F;&#x2F; @7</span><br><span class="line">            try &#123;</span><br><span class="line">                Result result &#x3D; invoker.invoke(invocation);     &#x2F;&#x2F; @8</span><br><span class="line">                RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true);    &#x2F;&#x2F; @9</span><br><span class="line">                return result;</span><br><span class="line">            &#125; catch (RuntimeException t) &#123;</span><br><span class="line">                RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false);</span><br><span class="line">                throw t;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; finally &#123;</span><br><span class="line">            if (max &gt; 0) &#123;</span><br><span class="line">                synchronized (count) &#123;</span><br><span class="line">                    count.notify();     &#x2F;&#x2F; @10</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>代码@1：从Invoker中获取消息端URL中的配置的actives参数，为什么从Invoker中获取的Url是消费端的Url呢？这是因为在消费端根据服务提供者URL创建调用Invoker时，会用服务提供者URL，然后合并消费端的配置属性，其优先级 -D &gt; 消费端 &gt; 服务端。其代码位于：、<br>RegistryDirectory#toInvokers<br>URL url = mergeUrl(providerUrl);</p>
<p>代码@2：根据服务提供者URL和调用服务提供者方法，获取RpcStatus。</p>
<p>代码@3：获取接口调用的超时时间，默认为1s。</p>
<p>代码@4：获取当前消费者，针对特定服务，特定方法的并发调用度，active值。</p>
<p>代码@5：如果当前的并发 调用大于等于允许的最大值，则针对该RpcStatus申请锁，并调用其wait(timeout)进行等待，也就是在接口调用超时时间内，还是未被唤醒，则直接抛出超时异常。</p>
<p>代码@6：判断被唤醒的原因是因为等待超时，还是由于调用结束，释放了”名额“，如果是超时唤醒，则直接抛出异常。</p>
<p>代码@7：在一次服务调用前，先将 服务名+方法名对应的RpcStatus的active加一。</p>
<p>代码@8：执行RPC服务调用。</p>
<p>代码@9：记录成功调用或失败调用，并将active减一。</p>
<p>代码@10：最终成功执行，如果开启了actives机制(dubbo:referecnce actives=””)时，唤醒等待者。</p>
<blockquote>
<p>总结：&lt; dubbo:reference actives=””/&gt; 是控制消费端对 单个服务提供者单个服务允许调用的最大并发度。该值的取值不应该大于&lt; dubbo:service executes=””/&gt;的值，并且如果消费者机器的配置，如果性能不尽相同，不建议对该值进行设置。</p>
</blockquote>
</div>

			<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
			<script>
			var isMobile = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
			if (!isMobile) {
			    var btw = new BTWPlugin();
			    btw.init({
			        "id": "vip-container",
			        "blogId": "18019-1573088808868-542",
			        "name": "中间件兴趣圈",
			        "qrcode": "https://img-blog.csdnimg.cn/20190314214003962.jpg",
			        "keyword": "more"
			    });
			}
			</script>
		
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/posts/fd487dee.html" rel="next" title="源码分析Dubbo服务调用-服务提供者如何处理请求命令与再谈Invoker">
                <i class="fa fa-chevron-left"></i> 源码分析Dubbo服务调用-服务提供者如何处理请求命令与再谈Invoker
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/70022ae6.html" rel="prev" title="源码分析Dubbo异步调用与事件回调机制">
                源码分析Dubbo异步调用与事件回调机制 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">139</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1%E3%80%81%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90ExecuteLimitFilter"><span class="nav-number">1.</span> <span class="nav-text">1、源码分析ExecuteLimitFilter</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2%E3%80%81%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90ActiveLimitFilter"><span class="nav-number">2.</span> <span class="nav-text">2、源码分析ActiveLimitFilter</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">中间件兴趣圈</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("NNEhOL0iOcflg8f1U3HUqiCq-gzGzoHsz", "7kSmkbbb3DktmHALlShDsBUF");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
